<?php
/**
 * 自动加载类
 * @author Yangdong Zhang <zhangyangdong@gouuse.cn>
 * @time 2018/10/12 15:43
 */

spl_autoload_register(function ($class) {

    $path  = explode('\\', $class);
    $class = array_pop($path);
    $pathPrefix = '';
    if ($path) {
        foreach ($path as &$v) {
            $v = lcfirst($v);
        }
        $pathPrefix = implode('/', $path);
    }
    $namespace = $pathPrefix.'/'.$class;
    $file = join('', [ROOT_PATH, '/', $namespace, '.php']);
    if (is_file($file)) {
        include_once $file;
    }
});